<!-- 巡检一览-巡检趋势分析 -->
<template>
  <div style="width: 100%; height: 100%; padding-top: 20px; box-sizing: border-box">
    <div ref="chartDom" style="width: 100%; height: 100%"></div>
  </div>
</template>
<script>
import { baseLineProps } from '@/config/baseEchartsConf';
const chartOptions = JSON.parse(JSON.stringify(baseLineProps));
const taskNameMap = new Map()
  .set('uavTask', '火警')
  .set('airPortTask', '故障')
  .set('robotTask', '监管')
  .set('feedback', '反馈')
  .set('pass', '屏蔽')
  .set('otherTask', '其他');
export default {
  data() {
    return {
      trendData: [],
      chartInstance: null
    };
  },
  mounted() {
    // eslint-disable-next-line no-undef, new-cap
    this.chartInstance = new echarts.init(this.$refs.chartDom);
    const res = {
      code: 200,
      success: true,
      data: {
        uavTask: [
          {
            month: 1,
            task_count: 2
          },
          {
            month: 2,
            task_count: 1
          },
          {
            month: 3,
            task_count: 8
          },
          {
            month: 4,
            task_count: 95
          },
          {
            month: 5,
            task_count: 79
          },
          {
            month: 6,
            task_count: 41
          },
          {
            month: 7,
            task_count: 11
          },
          {
            month: 8,
            task_count: 5
          },
          {
            month: 9,
            task_count: 3
          },
          {
            month: 10,
            task_count: 7
          },
          {
            month: 11,
            task_count: 1
          },
          {
            month: 12,
            task_count: 3
          }
        ],
        airPortTask: [
          {
            month: 1,
            task_count: 0
          },
          {
            month: 2,
            task_count: 6
          },
          {
            month: 3,
            task_count: 6
          },
          {
            month: 4,
            task_count: 13
          },
          {
            month: 5,
            task_count: 99
          },
          {
            month: 6,
            task_count: 87
          },
          {
            month: 7,
            task_count: 14
          },
          {
            month: 8,
            task_count: 21
          },
          {
            month: 9,
            task_count: 1
          },
          {
            month: 10,
            task_count: 3
          },
          {
            month: 11,
            task_count: 2
          },
          {
            month: 12,
            task_count: 2
          }
        ],
        robotTask: [
          {
            month: 1,
            task_count: 0
          },
          {
            month: 2,
            task_count: 0
          },
          {
            month: 3,
            task_count: 0
          },
          {
            month: 4,
            task_count: 0
          },
          {
            month: 5,
            task_count: 0
          },
          {
            month: 6,
            task_count: 0
          },
          {
            month: 7,
            task_count: 0
          },
          {
            month: 8,
            task_count: 0
          },
          {
            month: 9,
            task_count: 0
          },
          {
            month: 10,
            task_count: 0
          },
          {
            month: 11,
            task_count: 0
          },
          {
            month: 12,
            task_count: 0
          }
        ],
        pass: [
          {
            month: 1,
            task_count: 2
          },
          {
            month: 2,
            task_count: 3
          },
          {
            month: 3,
            task_count: 4
          },
          {
            month: 4,
            task_count: 1
          },
          {
            month: 5,
            task_count: 10
          },
          {
            month: 6,
            task_count: 66
          },
          {
            month: 7,
            task_count: 10
          },
          {
            month: 8,
            task_count: 33
          },
          {
            month: 9,
            task_count: 0
          },
          {
            month: 10,
            task_count: 22
          },
          {
            month: 11,
            task_count: 11
          },
          {
            month: 12,
            task_count: 22
          }
        ],
        feedback: [
          {
            month: 1,
            task_count: 0
          },
          {
            month: 2,
            task_count: 0
          },
          {
            month: 3,
            task_count: 0
          },
          {
            month: 4,
            task_count: 0
          },
          {
            month: 5,
            task_count: 0
          },
          {
            month: 6,
            task_count: 0
          },
          {
            month: 7,
            task_count: 0
          },
          {
            month: 8,
            task_count: 0
          },
          {
            month: 9,
            task_count: 0
          },
          {
            month: 10,
            task_count: 0
          },
          {
            month: 11,
            task_count: 0
          },
          {
            month: 12,
            task_count: 0
          }
        ],
        otherTask: [
          {
            month: 1,
            task_count: 0
          },
          {
            month: 2,
            task_count: 0
          },
          {
            month: 3,
            task_count: 0
          },
          {
            month: 4,
            task_count: 9
          },
          {
            month: 5,
            task_count: 9
          },
          {
            month: 6,
            task_count: 0
          },
          {
            month: 7,
            task_count: 0
          },
          {
            month: 8,
            task_count: 1
          },
          {
            month: 9,
            task_count: 0
          },
          {
            month: 10,
            task_count: 0
          },
          {
            month: 11,
            task_count: 0
          },
          {
            month: 12,
            task_count: 0
          }
        ]
      },
      msg: '操作成功'
    };
    this.trendData = res.data;
    this.initOptions();
  },
  methods: {
    initOptions() {
      const self = this;
      chartOptions.xAxis[0].data = this.trendData.uavTask.map(v => `${v.month}月`);
      chartOptions.yAxis.name = '';
      chartOptions.series = Object.keys(this.trendData).map(v => {
        return {
          ...chartOptions.series[0],
          name: taskNameMap.get(v),
          data: self.trendData[v].map(t => t.task_count)
        };
      });
      this.chartInstance.setOption({
        ...chartOptions
      });
    }
  }
};
</script>
<style lang="scss" scoped></style>
